package com.holyn.guofang.view.distinguish;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.holyn.guofang.R;
import com.holyn.guofang.model.webhttp.wo.BrandBulletinWo;
import com.holyn.guofang.view.BaseActivity;
import com.holyn.guofang.viewcommon.activity.PinchImageView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Holyn on 2017/9/8.
 */

public class ProductDetailNoticesImagesAvtivity extends BaseActivity {
    public static String INTENT_KEY_BRAND_BULLET_WO = "INTENT_KEY_BRAND_BULLET_WO";

    @BindView(R.id.tv_content)
    TextView tvContent;
    @BindView(R.id.iv_turn_left)
    ImageView ivTurnLeft;
    @BindView(R.id.piv)
    PinchImageView piv;
    @BindView(R.id.iv_turn_right)
    ImageView ivTurnRight;

    private BrandBulletinWo brandBulletinWo;
    private List<BrandBulletinWo.DataBean.BulletinInfoBean> bulletList;
    private String classAndNo;

    private int curPosition = 0;

    public static void start(Activity activity, BrandBulletinWo brandBulletinWo){
        Intent intent = new Intent(activity, ProductDetailNoticesImagesAvtivity.class);
        intent.putExtra(INTENT_KEY_BRAND_BULLET_WO, brandBulletinWo);
        activity.startActivity(intent);
    }

    @Override
    protected int getLayoutResID() {
        return R.layout.activity_product_detail_notises_images;
    }

    @Override
    protected void onMyCreate() {
        ButterKnife.bind(this);
        showToolbar("商标公告");

        brandBulletinWo = (BrandBulletinWo) getIntent().getSerializableExtra(INTENT_KEY_BRAND_BULLET_WO);
        BrandBulletinWo.DataBean dataBean = brandBulletinWo.getData();
        bulletList = dataBean.getBulletinInfo();
        classAndNo = "第"+dataBean.getMarkClass()+"类第"+dataBean.getMarkNo()+"号\n";

        tvContent.setText(classAndNo + bulletList.get(0).getPublishName() + "\n出版日期：" + bulletList.get(0).getPublishDate());
        Glide.with(ProductDetailNoticesImagesAvtivity.this).load(bulletList.get(0).getBulletinImage())
//                .error(R.drawable.ic_empty_image)
                .into(piv);
    }

    @OnClick({R.id.iv_turn_left, R.id.iv_turn_right})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_turn_left:
                curPosition --;
                if (curPosition == 0){
                    ivTurnLeft.setVisibility(View.INVISIBLE);
                }
                ivTurnRight.setVisibility(View.VISIBLE);
                break;
            case R.id.iv_turn_right:
                curPosition ++;
                if (curPosition == (bulletList.size() - 1)){
                    ivTurnRight.setVisibility(View.INVISIBLE);
                }
                ivTurnLeft.setVisibility(View.VISIBLE);
                break;
        }
        tvContent.setText(classAndNo + bulletList.get(curPosition).getPublishName() + "\n出版日期：" + bulletList.get(curPosition).getPublishDate());
        Glide.with(ProductDetailNoticesImagesAvtivity.this).load(bulletList.get(curPosition).getBulletinImage())
//                .error(R.drawable.ic_empty_image)
                .into(piv);

    }
}
